/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package grant;

import edu.ipfw.cs590.cheat.GrantRegistrationRequest;
import edu.ipfw.cs590.cheat.GrantRegistrationRequestResponse;
import edu.ipfw.cs590.cheat.AssignmentManagementInterface;
import edu.ipfw.cs590.cheat.RegisteredPerson;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;

/**
 *
 * @author rrm46582
 */
public class Main {
    static List<RegisteredPerson> pendingUsers;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        try
        {
            // TODO code application logic here
            int sessId = 218;
            callGrant(sessId, "f@g.com");
        } 
        catch (Exception ex)
        {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }




 private static void callGrant(int sessId, String user)
 {
    URL wsdlURL = null;
        try
		{
			wsdlURL = new URL("http://robinrmcomputer:8080/CheatApp-war/AssignmentManagementService?wsdl");
            QName serviceQName = new QName("HTTP://cheat.cs590.ipfw.edu","AssignmentManagementService");
			QName portQName =    new QName("HTTP://cheat.cs590.ipfw.edu","AssignmentManagementSOAP");
            Service service = null;
            service = Service.create(wsdlURL, serviceQName);

            AssignmentManagementInterface jiPort =
                    (AssignmentManagementInterface)  service.getPort(portQName,AssignmentManagementInterface.class);


            GrantRegistrationRequest grant = new GrantRegistrationRequest();

            grant.setPendingUser(user);
            GrantRegistrationRequestResponse answer = jiPort.grantRegistrationRequest(grant, new Integer(sessId).toString());

            System.out.println("Access for:" + user + " " + answer.isGrantResult());
		}
		catch (MalformedURLException e)
		{
			e.printStackTrace();
		}
 }

}
